package com.qifenqian.turbot.module.ui.marketing

import android.app.Activity
import android.content.Intent
import android.support.v7.widget.LinearLayoutManager
import com.qifenqian.turbot.R
import com.qifenqian.turbot.base.BaseActivity
import com.qifenqian.turbot.module.adapter.itemdecoration.LinearItemDecoration
import com.qifenqian.turbot.module.adapter.marketing.DiscountDishAdapter
import com.qifenqian.turbot.module.contract.MarketingContract
import com.qifenqian.turbot.module.entity.response.marketing.DiscountDishEntity
import com.qifenqian.turbot.module.presenter.MarketingPresenter
import kotlinx.android.synthetic.main.activity_discount_dish.*

/**
 * @author H
 * @createDate 2019/1
 * @description 单品折扣
 * @see
 * @since
 */
class DiscountDishActivity : BaseActivity<MarketingPresenter, MarketingContract.View>(), MarketingContract.View {

    companion object {
        fun startThis(activity: Activity) {
            val intent = Intent(activity, DiscountDishActivity::class.java)
            activity.startActivity(intent)
        }
    }

    override fun bindLayoutId(): Int {
        return R.layout.activity_discount_dish
    }

    override fun bindPresenter(): MarketingPresenter? {
        return MarketingPresenter(this, this)
    }

    private var data: MutableList<String> = mutableListOf("aaa", "bbb", "ccc")
    private var mDiscountDishAdapter: DiscountDishAdapter? = null
    override fun initial() {
        btn_discount_dish_add.setOnClickListener {
            DiscountDishEditActivity.startThis(this, ACTION_DISCOUNT_ADD)
        }
        mDiscountDishAdapter = DiscountDishAdapter(data)
        rv_discount_dish.layoutManager = LinearLayoutManager(this)
        rv_discount_dish.addItemDecoration(LinearItemDecoration(this, spaceWidth = 30))
        rv_discount_dish.adapter = mDiscountDishAdapter
        mPresenter?.getDiscountDishes()
//        val view = LayoutInflater.from(this).inflate(R.layout.layout_error, rv_discount_dish, false)
//        view.btn_error_retry.setOnClickListener {
//
//        }
//        mDiscountDishAdapter!!.emptyView = view

        // TODO: 2019/1/16 写在mPresenter结果回调之后,在测试是否有用,无用则在布局中删除ViewStub
//        if (data.isNullOrEmpty()) {
//            rv_discount_dish.visibility = View.GONE
//            val viewStub = vs_discount_dish.inflate()
//            viewStub!!.btn_error_retry.setOnClickListener {
//                mPresenter.
//            }
//        }
    }

    override fun getDiscountDishesResult(isSuccess: Boolean, code: Int, msg: String?, discountDishEntity: DiscountDishEntity?) {
        if (isSuccess) {

        }
    }
}
